package com.lmx.persistence.service;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.lmx.repoDomain.tmodel.DrugFormType;

/**
 * 药品剂型
 * @author ytche
 *
 * @param <T>
 */
@Service
@Scope("prototype")
public class DrugFormTypeService {
	
	private Log logger = LogFactory.getLog(this.getClass());
	@PersistenceContext
	private EntityManager em;
	
	public List<DrugFormType> findAll(Long parentId){
		String queryStr=parentId==null?"select c from DrugFormType c where c.parent = null":
			"select c from DrugFormType c where  c.parent.id= ?1";
		Query query=this.em.createQuery(queryStr);
		return parentId==null?query.getResultList():query.setParameter(1, parentId).getResultList();
	}

	public DrugFormType findOne(Long id) {
		return this.em.find(DrugFormType.class, id);
	}
}
